/**
 * Copyright(c) ${copyrightYear} ${company}
 * All rights reserved.
 * Created on ${date}
 */
package ${package};

import java.io.Serializable;
import javax.persistence.MappedSuperclass;

/**
 * 所有实体类的父类，包含一个ID主键
 * 
 * @author ${author}
 */
@MappedSuperclass
public abstract class BaseEntity<K> implements Serializable{
	/**
	 * 主键
	 */
	public abstract K getId();

	/**
	 * 根据getID重写hashCode方法
	 * @return int hashcode
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
		return result;
	}
	/**
	 * 根据getID重写equals方法
	 * @return int hashcode
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final BaseEntity<?> other = (BaseEntity<?>) obj;
		if (getId() == null) {
			if (other.getId() != null)
				return false;
		} else if (!getId().equals(other.getId()))
			return false;
		return true;
	}
}
